package com.bite.demo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public boolean login(String userName, String password, HttpSession session) {
        if(userName==null||userName.equals("")) {
            return false;
        }
        if(password==null||password.equals("")) {
            return false;
        }
        if("zhangsan".equals(userName)&&"123456".equals(password)) {
            session.setAttribute("userName",userName);
            return true;
        }
        //密码验证成功之后 把名字存入Session
        return false;
    }

    @RequestMapping("/getName")
    public String getName(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        return "接收到参数："+userName;
    }
}
